<?php

/**
 * Created by PhpStorm.
 * User: wukent
 * Date: 2017/9/20
 * Time: 下午4:05
 */
class CommentAction extends ApiAction
{

    protected $commentMod;
    protected $commentphotoMOD;
    protected function _initialize() {
        parent::_initialize();
        $this->commentMod = D("MerchantComment");
        $this->commentphotoMOD = D("MerchantCommentPhoto");
    }

    public function getlist(){
        $merchant_id = empty($_POST['merchant_id'])?0:$_POST['merchant_id'];
        $page = empty($_POST['curpage'])?1:$_POST['curpage'];
        $pernum = empty($_POST['cursize'])?10:$_POST['cursize'];
        // echo json_encode(array('merchant_id'=>$merchant_id,'page'=>$page,'pernum'=>$pernum));die;

        if ($merchant_id>0){
            $commentlist = $this->commentMod->numList($merchant_id,$page,$pernum);
            // echo json_encode($commentlist);die;
            if ($commentlist){
                foreach ($commentlist as $key=>$value){
                    $commentlist[$key]['photolist'] = $this->commentphotoMOD->getList($value['comment_id']);
                }

                $this->rest($commentlist,1);


            }else{
                $this->rest('',17);
            }

        }else{
            $this->rest('',16);
        }



    }


    public function postinfo(){
        $merchant_id = empty($this->_post('merchant_id'))?0:$this->_post('merchant_id');
        $grade = $this->_post('grade');
        $details = $this->_post('details');
        if ($merchant_id>0){


            if ($grade>0 && !empty($details)){
                $info = $this->commentMod->entry($this->uid,$merchant_id);
                if ($info){
                    $this->rest('',1);
                }else{
                    $this->rest('',19);
                }

            }else{
                $this->rest('',18);
            }


        }else{
            $this->rest('',16);
        }

    }

}